package com.avic.rong.course.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.avic.rong.R;
import com.avic.rong.course.bean.PeiXunClassMuLuBean;
import com.bumptech.glide.Glide;
import com.example.minato.minastore.utils.AppUtils;

import java.util.List;

/**
 * Created by Chenjiaxin on 2019/8/18 10:31
 * E-Mail Address：16601203965@163.com
 */
public class ClassMuLuBgRvAdapter extends RecyclerView.Adapter<ClassMuLuBgRvAdapter.BgRvViewHolder> {

    private Context context;
    private List<PeiXunClassMuLuBean.DatasBean.HourListBean> bgList;
    private LayoutInflater inflater;

    public ClassMuLuBgRvAdapter(Context context, List<PeiXunClassMuLuBean.DatasBean.HourListBean> bgList) {
        this.context = context;
        this.bgList = bgList;
        this.inflater = LayoutInflater.from(context);
    }

    @NonNull
    @Override
    public BgRvViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = inflater.inflate(R.layout.view_class_mulu_item, viewGroup, false);
        return new BgRvViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull BgRvViewHolder holder, int i) {
        Glide.with(context).load(AppUtils.COURSE_IMAGE_URL + bgList.get(i).getContent()).placeholder(R.mipmap.online_default).into(holder.bgImg);
        PeiXunClassMuLuBean.DatasBean.HourListBean hourListBean = bgList.get(i);
        holder.title.setText(hourListBean.getName());
        holder.time.setText("时长：" + hourListBean.getTotalTime());
        holder.itemView.setOnClickListener(new MuLuListener(hourListBean));
    }

    @Override
    public int getItemCount() {
        return bgList.size();
    }


    class MuLuListener implements View.OnClickListener{
        PeiXunClassMuLuBean.DatasBean.HourListBean hourListBean;

        public MuLuListener(PeiXunClassMuLuBean.DatasBean.HourListBean hourListBean) {
            this.hourListBean = hourListBean;
        }

        @Override
        public void onClick(View v) {
//            context.startActivity(VideoPlayerActivity.getIntent(context,hourListBean.getName(),hourListBean.getContent(),));
        }
    }

    class BgRvViewHolder extends RecyclerView.ViewHolder {
        ImageView bgImg, startImg;
        TextView title, time;

        public BgRvViewHolder(@NonNull View itemView) {
            super(itemView);
            bgImg = itemView.findViewById(R.id.mulu_img);
            startImg = itemView.findViewById(R.id.mulu_start);
            title = itemView.findViewById(R.id.mulu_title);
            time = itemView.findViewById(R.id.mulu_time);
        }
    }
}
